package pikasial.utils;

import java.io.File;

public class ExtensionsImages {

    public static final int JPEG = 0;
    public static final int JPG = 1;
    public static final int GIF = 2;
    public static final int BMP = 4;
    public static final int PNG = 3;
    protected static final String[] extensions = {"jpeg", "jpg", "gif", "png", "bmp"};

    private ExtensionsImages() {
    }

    public static boolean isValidExtension(String ext) {
    	if (ext == null) {
            return false;
        }
        for (int i = 0; i < extensions.length; i++) {
            if (ext.toLowerCase().equals(extensions[i])) {
                return true;
            }
        }
        return false;
    }

    public static String getExtension(int extType) {
        return extensions[extType];
    }

    public static String getExtensionFichier(File f) {
        String name = f.getName();
        int lastPt = name.lastIndexOf('.');
        if (lastPt > 0 && lastPt < name.length() - 1) {
            return name.substring(lastPt + 1);
        } else {
            return null;
        }
    }

    public static int getExtensionType(final String ext) {
    	String str = ext.toLowerCase();
    	int type = -1;
    	for (int i=0; i<extensions.length; i++) {
    		if (str.equals(extensions[i])) {
    			type = i;
    			break;
    		}
    	}
    	return type;
    }

    public static String[] getExtensions() {
        return extensions;
    }
}
